#!/usr/bin/env python

import os,sys,time

definepath=os.getcwd()

try:

 if sys.argv[1]=='install':
   print """
Discovery setup script.

Some things to note before running Discovery, you must install the following:

Metasploit (for client attack)
SQLite3 (for database)

There are other requirements however, Discovery will check for them and if
your missing any, Discovery will install it for you.
   """

   print "Metasploit directory example: /pentest/exploits/framework3/"

   try:
      metasploitpath=raw_input("\nEnter the path to the metasploit directory\nHit enter for default (/Pentest/framework-3.2/): ")
      if metasploitpath=='':
          metasploitpath="/Pentest/framework-3.2/"

      os.system("echo METASPLOIT_PATH " + metasploitpath + " > discovery.conf")

      print "Metasploit directory set....."

      manager_password = raw_input("Please enter the Manager's password : ")
      os.system("echo MANAGER_PASSWORD " + manager_password + " >> discovery.conf")

      print "Manager's password set....."


      print "No guarentee this will successfully install all dependencies correctly\nyou may need to install some manually..\nDifferent Linux OS require different things to work.\n"

      installstuff=raw_input("Would you like to attempt all dependencies, yes or no: ")

      if installstuff=='yes':
         print 'Installing requirements needed for Discovery'

         print 'Installing Module for Python Called "PExpect"'
         pexpect0=os.system('wget http://downloads.sourceforge.net/pexpect/pexpect-2.3.tar.gz;tar -zxvf pexpect-2.3.tar.gz;cd pexpect-2.3;python setup.py install;cd ..;rm -rf pexpect-2.3;rm pexpect-2.3.tar.gz')
         print 'Installed! Moving on...'

         print 'Installing SQLite3'
         sqlite3=os.system('cd /usr/local/bin/;ln -s tclsh8.4 tclsh')
         sqlite4=os.system('wget http://www.sqlite.org/sqlite-3.5.7.tar.gz;tar -zxvf sqlite-3.5.7.tar.gz;cd sqlite-3.5.7;./configure --prefix=/usr/local && make && make install;cd ..;rm sqlite-3.5.7.tar.gz;rm -rf sqlite-3.5.7')
         sqlite3=os.system('wget http://rubyforge.org/frs/download.php/17097/sqlite3-ruby-1.2.1.tar.gz;tar -zxvf sqlite3-ruby-1.2.1.tar.gz;cd sqlite3-ruby-1.2.1;ruby setup.rb config;ruby setup.rb setup;ruby setup.rb install;cd ..;rm  sqlite3-ruby-1.2.1.tar.gz;rm -rf sqlite3-ruby-1.2.1')
         print 'SQLite3 installed..Moving on...'

         print "\nFinished with setup...you can now run Discovery, make sure everything installed properly...\n\n"

      elif installstuff=='no':
         print """############################################
#                                          #
#          EXITING DISCOVERY SETUP         #
#                                          #
############################################"""
      else:
         print """############################################
#                                          #
#          PLEASE TYPE YES OR NO           #
#                                          #
############################################"""


   except KeyboardInterrupt:
      print "\n\nExiting Discovery setup...\n"

except IndexError:
     print """
Discovery Setup and Installation

After installation, Discovery should be fully functional.

USAGE: python setup.py install
    """


